import Vue from "vue";
import Axios from "axios";
import VueAxios from "vue-axios";
import { Message } from "element-ui";

Vue.use(VueAxios, Axios);

Axios.defaults.withCredentials = true;
Axios.defaults.baseURL = "http://localhost:8080";
Axios.interceptors.response.use(
  (res) => {
    console.log("拦截器拦截到", res.data);
    return res;
  },
  (error) => {
    if (error && error.response) {
      switch (error.response.status) {
        case 404: {
          console.log("404异常");
          break;
        }
        case 930: {
          Message.info("过滤器权限拦截异常：" + error.response.data);
          break;
        }
        case 960: {
          Message.warning("过滤器身份认证异常；" + error.response.data);
          break;
        }
        case 999: {
          Message.error("处理器业务流程异常：" + error.response.data);
          break;
        }
        default: {
          console.log("未知异常" + error.response.data);
        }
      }
    }

    throw error;

    // throw "没有找到啊";
    // return Promise.reject(error)
  }
);

export default Axios;
